﻿@model IEnumerable<ArivisTests.Models.TestCase>
@using ArivisTests.Views;

<table class="editor-table">
@{
var groups = Model.GroupBy(x => x.User);
var orderedGroups = groups.OrderByDescending(group => group.Where(testcase => testcase.Result == null).Sum(testcase => testcase.Scenario.Duration));
   
foreach (var userGroup in orderedGroups)
{
    var userName = userGroup.Key == null ? "[no tester]" : userGroup.Key.UserName;
    var done = userGroup.Count(test => test.Result != null);
    var resultGroups = userGroup.GroupBy(test => test.Result);
    int progress = 100 * done / userGroup.Count();
        <tr>
            <th style="vertical-align:top">@userName</th>
            <th style="font-weight:normal; padding-right:0;">
                @Html.TestProgressText(userGroup)
            </th>
        </tr>
    foreach (var resultGroup in resultGroups)
    {
        var resultName = resultGroup.Key == null ? "no result" : resultGroup.Key.Name;
        <tr>
        <td class="editor-label">
            @resultName
        </td>
        <td class="editor-field" style="vertical-align:top">
            <div style="max-height:100px; overflow-y: auto;">
             @Html.LinkedItems("Edit", "TestCase", userGroup.Where(x => x.Result == resultGroup.Key).OrderBy(test => test.Order), false)
            </div>
        </td>
        </tr>
    }
    <tr><th colspan="2" style="height:1em;"></th></tr>
}
}
</table>

